$(function () {

    hr.regComponent('header3', {
        init: function () {
            this.nav().init();
            this.bindResize();
        },
        nav: function () {
            var _nav = {
                menuBtn: $('.header3-menuBtn'),
                nav: $('.js-nav'),
                menu: $('.header3-nav'),
                menuLi: $('.header3-nav li'),
                menuLi2: $('.header3-nav2 li'),
                menuLink: $('.header3-nav li > a'),
                init: function () {
                    var _this = this;
                    this.resize();
                },
                resize: function (width) {
                    this.menuLink.off('click');
                    this.menuLi.off('mouseenter mouseleave');
                    this.menu.find('.sub').stop(true, true).slideUp(0);

                    this.menuLi.each(function (index, val) {
                        if ($(this).find('.header3-navsub').length) {
                            $(this).find('.el-icon-arrow-down').show();
                        }
                    });
                    this.menuLi.on('mouseenter', function () {
                        if ($(this).find('.header3-navsub').length) {
                            $(this).find('.header3-navsub').stop(true, true).slideDown('fast');
                            $(this).addClass('hover');
                        }
                    });
                    this.menuLi.on('mouseleave', function () {
                        $(this).find('.header3-navsub').stop(true, true).slideUp('fast');
                        $(this).removeClass('hover');
                    });

                    this.menuLi2.on('mouseenter', function () {
                        if ($(this).find('.header3-navsub').length) {
                            $(this).find('.header3-navsub').stop(true, true).slideDown('fast');
                        }
                    });
                    this.menuLi2.on('mouseleave', function () {
                        $(this).find('.header3-navsub').stop(true, true).slideUp('fast');
                    });

                    $(window).on('scroll', function (event) {
                        var _scrollTop = $(window).scrollTop();
                        if (_scrollTop > 0) {
                            $('.header3').addClass('down');
                        } else {
                            $('.header3').removeClass('down');
                        }
                    });
                }
            };

            return _nav;
        },
        bindResize: function () {
            var resizeTimer = null;
            var _this = this;
            $(window).on('resize', function () {
                if (resizeTimer) {
                    clearTimeout(resizeTimer);
                }
                resizeTimer = setTimeout(function () {
                    _this.nav().resize();
                }, 100);
            });
        }
    });

});

$(function () {

    hr.regComponent('dropmenurel01', {
        init: function () {
            this.simulateMenu();
        },
        simulateMenu: function () {
            // 模拟下拉菜单 单选
            var $dropmenu = $('.js-dropmenu');
            $dropmenu.each(function (index, item) {
                var moduleName = $(item).attr('data-modulename') || 'dropmenurel01';
                $(item).on('click', '.' + moduleName + '-tit', function (e) {
                    e.stopPropagation();
                    var $parent = $(e.delegateTarget);
                    var $this = $(this);
                    var $options = $parent.find('.' + moduleName + '-options');
                    var $window = $(window);
                    var down = ($parent.offset().top - $window.scrollTop() + $parent.innerHeight() + $options.innerHeight() <= $window.innerHeight());

                    $options.css({
                        'height': 'auto'
                    });

                    if (down) {
                        $parent.addClass('down');
                        $options.css({
                            'top': $parent.outerHeight() - 1 + 'px',
                            'bottom': 'auto',
                            'min-width': $parent.innerWidth() + 'px',
                            'height': $options.innerHeight() + 2
                        });
                    } else {
                        $parent.addClass('up');
                        $options.css({
                            'top': 'auto',
                            'bottom': $parent.outerHeight() - 1 + 'px',
                            'min-width': $parent.innerWidth() + 'px',
                            'height': $options.innerHeight() + 2
                        });
                    }

                    if ($parent.hasClass('dropmenurel01_disabled')) {
                        return false;
                    }

                    $('.js-dropmenu-options').not($options).slideUp('fast');
                    $options.slideToggle('fast');

                    if ($parent.hasClass('focusInput')) {
                        $parent.removeClass('arrowIcon focusInput');
                    } else {
                        $dropmenu.removeClass('focusInput arrowIcon');
                        $parent.addClass('arrowIcon focusInput');
                    }
                });
                $(item).on('click', '.' + moduleName + '-options li', function (e) {
                    e.stopPropagation();
                    var $parent = $(e.delegateTarget);
                    var $tit = $parent.find('.' + moduleName + '-tit');
                    var $input = $parent.find('input[type="hidden"]');

                    if ($(this).hasClass('empty-data')) {
                        return false;
                    }

                    if ($(this).hasClass('parent_li')) {
                        hr.util.treeFun();
                    }

                    $tit.find('span').html($(this).text());
                    $input.val($(this).data('value'));
                    $('.js-dropmenu-options').slideUp('fast');

                    $parent.addClass('focusInput doneTit');
                    $parent.removeClass('arrowIcon');
                });
                $(item).on('click', '.' + moduleName + '-options', function (e) {
                    e.stopPropagation();
                    if ($('.js-dropmenu').find('.input').length) {
                        return false;
                    }
                });
                $('body').on('click', function (e) {
                    $('.js-dropmenu-options').slideUp('fast');

                    $('.js-dropmenu').removeClass('arrowIcon focusInput');

                });
            });

            // 模拟下拉菜单 多选
            var $dropmenu2 = $('.js-dropmenu2');
            $dropmenu2.each(function (index, item) {
                var moduleName = $(item).attr('data-modulename') || 'dropmenurel01';
                $(item).on('click', '.' + moduleName + '-tit', function (e) {
                    e.stopPropagation();
                    var $parent = $(e.delegateTarget);
                    var $this = $(this);
                    var $options = $parent.find('.' + moduleName + '-options');
                    var $window = $(window);
                    var down = ($parent.offset().top - $window.scrollTop() + $parent.innerHeight() + $options.innerHeight() <= $window.innerHeight());

                    $options.css({
                        'height': 'auto'
                    });

                    if (down) {
                        $parent.addClass('down');
                        $options.css({
                            'top': $parent.outerHeight() - 1 + 'px',
                            'bottom': 'auto',
                            'min-width': $parent.innerWidth() + 'px',
                            'height': $options.innerHeight() + 2
                        });
                    } else {
                        $parent.addClass('up');
                        $options.css({
                            'top': 'auto',
                            'bottom': $parent.outerHeight() - 1 + 'px',
                            'min-width': $parent.innerWidth() + 'px',
                            'height': $options.innerHeight() + 2
                        });
                    }

                    if ($parent.hasClass('dropmenurel01_disabled')) {
                        return false;
                    }

                    $('.js-dropmenu-options2').not($options).slideUp('fast');
                    $options.slideToggle('fast');

                    if ($parent.hasClass('focusInput')) {
                        $parent.removeClass('arrowIcon focusInput');
                    } else {
                        $dropmenu.removeClass('focusInput arrowIcon');
                        $parent.addClass('arrowIcon focusInput');
                    }
                });
                $(item).on('click', '.' + moduleName + '-options li', function (e) {
                    e.stopPropagation();
                    var $parent = $(e.delegateTarget);
                    var $tit = $parent.find('.' + moduleName + '-tit');
                    var $input = $parent.find('input[type="hidden"]');

                    if ($(this).hasClass('empty-data')) {
                        return false;
                    }

                    if ($(this).hasClass('parent_li')) {
                        hr.util.treeFun();
                    }

                    if ($(this).find('.checkbox-item').length) {
                        return;
                    }

                    $tit.find('span').html($(this).text());
                    $input.val($(this).data('value'));
                    $('.js-dropmenu-options2').slideUp('fast');

                    $parent.addClass('focusInput doneTit');
                    $parent.removeClass('arrowIcon');
                });
                $(item).on('click', '.' + moduleName + '-options', function (e) {
                    e.stopPropagation();
                    if ($('.js-dropmenu2').find('.input').length) {
                        return false;
                    }
                });
                $('body').on('click', function (e) {
                    $('.js-dropmenu-options2').slideUp('fast');

                    $('.js-dropmenu2').removeClass('arrowIcon focusInput');

                });
            });
        }
    });

});
$(function () {

    hr.regComponent('tabrel01', {
        init: function () {
            this.tabs();
        },
        tabs: function () {
            $('.js-tabs').each(function (index, item) {
                var $block = $(item);
                var moduleName = $block.attr('data-modulename') || 'tabrel01';
                $block.find('.' + moduleName + '-tit > .' + moduleName + '-item').on('click', function (e) {
                    if (!$(this).hasClass('' + moduleName + '-item__on')) {
                        var $currentTit = $block.find('.' + moduleName + '-tit > .' + moduleName + '-item__on');
                        var $currentDesc = $block.find('.' + moduleName + '-desc > .' + moduleName + '-item__on');
                        var $clickTit = $(this);
                        var $clickDesc = $($block.find('.' + moduleName + '-desc > .' + moduleName + '-item')[$clickTit.index()]);

                        $currentTit.removeClass('' + moduleName + '-item__on');
                        $clickTit.addClass('' + moduleName + '-item__on');
                        if ($block.hasClass('js-anim')) {
                            $currentDesc.stop().fadeOut(60, function () {
                                $(this).removeClass('' + moduleName + '-item__on');
                                $clickDesc.stop().fadeIn(60, function () {
                                    $(this).addClass('' + moduleName + '-item__on');
                                });
                            });
                        } else {
                            $currentDesc.removeClass('' + moduleName + '-item__on');
                            $clickDesc.addClass('' + moduleName + '-item__on');
                        }
                    }
                });
            });
        }
    });

});

// 初始化单选多选框状态，以及点击事件
$(function () {

    hr.regComponent('formrel03', {
        init: function () {
            this.initForm();
            this.bindInputChange();
        },
        initForm: function () {
            var $customRadioCheckbox = $('.js-custom-radio-checkbox');
            $customRadioCheckbox.each(function (index, item) {
                var moduleName = $(item).attr('data-modulename') || 'formrel03';
                var $form = $(item).find('input').filter(function () {
                    var type = $(this).attr('type');
                    return type === 'checkbox' || type === 'radio';
                });
                $form.each(function () {
                    var $this = $(this);
                    var $parent = $this.parent();
                    $parent.removeClass(moduleName + '-radio__checked ' + moduleName + '-chk__checked');
                    if ($this.attr('type') === 'radio') {
                        $this.prop('checked') && $parent.addClass(moduleName + '-radio__checked');
                        $this.prop('disabled') && $parent.addClass(moduleName + '-radio__disabled');
                    } else if ($this.attr('type') === 'checkbox') {
                        $this.prop('checked') && $parent.addClass(moduleName + '-chk__checked');
                        $this.prop('disabled') && $parent.addClass(moduleName + '-chk__disabled');
                    }
                });
            });
        },
        bindInputChange: function () {
            $('input').change(function (event) {
                event.stopPropagation();
                hr.component.formrel03.initForm();
            });
        }
    });
});

// ajax 
function $request(config, cb) {
    var bladeAuth = 'bearer eyJhbGciOiJIUzI1NiI
    sInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJ1c2VyX25hbWUiOiI4MzM0NThlNC01OTA0LTQyMTctYmE3NS02ODQ3MzBiNjlkNmYiLCJyZWFsX25hbWUiOiLlpaXlt7TpqawiLCJhdmF0YXIiOiJodHRwOi8vMTM5LjE5OC4xNS4yOTo0MDEwMi91c2VyLWNlbnRlci1vYXV0aC91c2VyL2F2YXRhci9zM19jYWMyMjBkNy0yNDcxLTQ0ZTYtYTQxZS1kYTI3MjhjMDE4YTcucG5nIiwiYXV0aG9yaXRpZXMiOlsiYmlkX2NlcnRpZmljYXRlX2FkbWluIiwiY2hhaW5zdWJfYWRtaW4iLCJiaWRfY2hhaW5fYWRtaW4iXSwiY2xpZW50X2lkIjoic2FiZXIiLCJjZXJ0aWZpY2F0ZV9zdGF0dXMiOm51bGwsInJvbGVfbmFtZSI6ImNoYWluc3ViX2FkbWluLGJpZF9jaGFpbl9hZG1pbixiaWRfY2VydGlmaWNhdGVfYWRtaW4iLCJsaWNlbnNlIjoicG93ZXJlZCBieSBibGFkZXgiLCJ1c2VyX3R5cGUiOm51bGwsInBvc3RfaWQiOiIxMTIzNTk4ODE3NzM4Njc1MjA4IiwiYXZhdGFyX3VybCI6bnVsbCwidXNlcl9pZCI6IjE1MDQ3NTg5MzM1MzU5ODE1NzAiLCJyb2xlX2lkIjoiMTEyMzU5ODgxNjczODY3NTIwMSIsInNjb3BlIjpbImFsbCJdLCJuaWNrX25hbWUiOiIiLCJleHAiOjE2NTU5OTkyODQsImRlcHRfaWQiOiIxIiwianRpIjoiYmI0NjQ0NTAtYmZhNi00MmNiLWIyZWEtZTg5ZWM2ZmRlNTllIiwiYWNjb3VudCI6IjgzMzQ1OGU0LTU5MDQtNDIxNy1iYTc1LTY4NDczMGI2OWQ2ZiJ9._SzjSe7rLTeqt6ht3mPeYD2F5UqZirOBAcEZjoYc2kc';
    $.ajax({
        url: config.url,
        method: (typeof(config.method) != "undefined" && config.method != "") ? config.method : 'get',
        beforeSend: function (req) {
            // test
            req.setRequestHeader('Auth', getUuid())
            req.setRequestHeader('Authorization', "bearer " + localStorage.getItem("ACCESS_TOKEN"))
            // req.setRequestHeader('Blade-Auth', "bearer " + localStorage.getItem("Blade-Auth"))
            req.setRequestHeader('Blade-Auth', bladeAuth)
            req.setRequestHeader('check', localStorage.getItem("username"))
        },
        headers: {
            'Content-Type': (typeof(config.contentType) != "undefined" && config.contentType != "") ? config.contentType : 'application/json;charset=UTF-8',
        },
        data: (typeof(config.data) != "undefined" && config.data != "") ? config.data : {}
    })
    .success(function (res) {
        if (res.code == 200 || res.code == 0) {
            cb(res.data)
        } else {
            if (res.msg){
                alert(res.msg);
            }
        }
    })
    .error(function (xhr, err) {
        var code = xhr.responseJSON.code;
        var msg = xhr.responseJSON.msg;
        if(code == 401 || xhr.responseJSON.status == 401){·
            /*alert("登录过期，请重新登录！");*/
            removeLocalStorage("ACCESS_TOKEN")
            window.location.href="/login.html";
        }else{
            if(!code) {
                if(xhr.responseJSON.status === 404) {
                    alert('服务器错误: 未找到相关服务');
                }
                else {
                    alert('服务器错误');
                }
            }
            else {
                alert('状态码' + code + "," + '信息:' + msg);
            }
        }
        console.log('状态码' + code + "," + '信息:' + msg);
    })
}

// url 取参数
function getUrlParams(key) {
    if(window.location.search == ""){
        return "";
    }
    var keyValue = "";
    var searchUrl = window.location.search;
    searchUrl = searchUrl.substring(1, searchUrl.length);
    var paramsArr = searchUrl.split("&");
    $.each(paramsArr, function(i, n){
        var thisArr = n.split("=");
        if(thisArr[0] == key){
            keyValue = thisArr[1];
        }
    });
    return keyValue;
}

// 设置表头菜单
function setTempHead(lstHead){
    var headArr = [];
    headArr.push('  <a href="" class="header-logo"><img src="/images/logo.png" alt=""/></a>');
    headArr.push('  <div class="header-nav">');
    headArr.push('  <ul class="fix">');
    $.each(lstHead, function(i, n){
        headArr.push('  <li><a href="' + n.linkUrl + '" class="v1">' + n.linkName + '</a></li>');
    });
    headArr.push('  </ul>');
    headArr.push('</div>');
    headArr.push('<div class="header-user">');
    headArr.push('  <a class="hd"><img src="images/head.png" alt="" /><span>管理员</span></a>');
    headArr.push('  <div class="dropdown-menu">');
    headArr.push('      <div class="icon-arrow"></div>');
    headArr.push('      <ul>');
    headArr.push('          <li><a href="/home.html" class="con"> <span>首页</span></a></li>');
    headArr.push('          <li><a href="/personalCenter.html" class="con"><span>资料编辑</span></a></li>');
    headArr.push('          <li><a onclick="logout()" class="con"><span>退出</span></a></li>');
    headArr.push('      <ul>');
    headArr.push('  </div>');
    headArr.push('</div>');
    $(".header").html(headArr.join(""));
}

// 设置表头菜单
function getTempHead(){
    var pathname = window.location.pathname;
    var module = getUrlParams("module") ? getUrlParams("module") : pathname.split("/")[1];
    var lstHead = [];
    if(module == "manage"){  // 业务管理子系统
        lstHead = [{linkName: "标识注册系统", linkUrl: "http://139.198.15.29:40103/registerApi/blade-auth/oauth/render/user_center"},
            {linkName: "标识解析系统", linkUrl: "/identification/resolver.html"},
            {linkName: "统一认证系统", linkUrl: "/userManager/index.html"},
            {linkName: "运行检测系统", linkUrl: "http://139.198.15.29:40103/api/blade-auth/oauth/render/user_center"},
            {linkName: "区块链浏览器", linkUrl: "/browser/home/index.html"}];
    }else if(module == "identification"){   // 标识注册系统
        lstHead = [{linkName: "业务管理子系统", linkUrl: "http://139.198.15.29:40103/bmsApi/blade-auth/oauth/render/user_center"},
            {linkName: "标识解析系统", linkUrl: "/identification/resolver.html"},
            {linkName: "统一认证系统", linkUrl: "/userManager/index.html"},
            {linkName: "运行检测系统", linkUrl: "http://139.198.15.29:40103/api/blade-auth/oauth/render/user_center"},
            {linkName: "区块链浏览器", linkUrl: "./subpage/browser-home.html"}];
    }else if(module == "userManager"){  // 统一认证系统
        lstHead = [{linkName: "业务管理子系统", linkUrl: "http://139.198.15.29:40103/bmsApi/blade-auth/oauth/render/user_center"},
            {linkName: "标识注册系统", linkUrl: "http://139.198.15.29:40103/registerApi/blade-auth/oauth/render/user_center"},
            {linkName: "标识解析系统", linkUrl: "/identification/resolver.html"},
            {linkName: "运行检测系统", linkUrl: "http://139.198.15.29:40103/api/blade-auth/oauth/render/user_center"},
            {linkName: "区块链浏览器", linkUrl: "/browser/home/index.html"}];
    }else if(module == "monitor"){   // 运行监测系统
        lstHead = [{linkName: "业务管理子系统", linkUrl: "http://139.198.15.29:40103/bmsApi/blade-auth/oauth/render/user_center"},
            {linkName: "标识注册系统", linkUrl: "http://139.198.15.29:40103/registerApi/blade-auth/oauth/render/user_center"},
            {linkName: "标识解析系统", linkUrl: "/identification/resolver.html"},
            {linkName: "统一认证系统", linkUrl: "/userManager/index.html"},
            {linkName: "区块链浏览器", linkUrl: "/browser/home/index.html"}];
    }
    setTempHead(lstHead);
}

function getRequestUrl(){
    var pathname = window.location.pathname;
    var module = getUrlParams("module") ? getUrlParams("module") : pathname.split("/")[1];
    var url = "";
    if(module == "manage") {       // 业务管理子系统
        url = "/bmsApi/blade-system";
    }else if(module == "identification"){   // 标识注册系统
        url = "/registerApi/blade-system";
    }else if(module == "userManager"){  // 统一认证系统
        url = "/user-manager/userApi";
    }else if(module == "monitor") {  // 运行监测系统
        url = "/api/blade-system";
    }
    return url;
}

function getRequestUrlUser(){
    var pathname = window.location.pathname;
    var module = getUrlParams("module") ? getUrlParams("module") : pathname.split("/")[1];
    var url = "";
    if(module == "manage") {       // 业务管理子系统
        url = "/bmsApi/blade-user";
    }else if(module == "identification"){   // 标识注册系统
        url = "/registerApi/blade-user";
    }else if(module == "monitor") {  // 运行监测系统
        url = "/api/blade-user";
    }
    return url;
}

function getLeftBar(){
    var pathname = window.location.pathname;
    var module = getUrlParams("module") ? getUrlParams("module") : pathname.split("/")[1];
    var url = "";
    if(module == "manage") {       // 业务管理子系统
        url = "/bmsApi/blade-system/menu/routes?parentId=";
    }else if(module == "identification"){   // 标识注册系统
        url = "/registerApi/blade-system/menu/routes?parentId=";
    }else if(module == "userManager"){  // 统一认证系统
        url = "/user-manager/userApi/menu/routes?parentId=";
    }else if(module == "monitor") {  // 运行监测系统
        url = "/api/blade-system/menu/routes?parentId=";
    }
    // 获取菜单信息
    $request({
        url: url,
        method: "get",
    }, function (res) {
        console.log(JSON.stringify(res));
        var lstLeftBar = res;
        console.log(JSON.stringify(lstLeftBar));
        if(lstLeftBar == "" || JSON.stringify(lstLeftBar) == "{}"){
            var leftBarArr = [];
            leftBarArr.push('<div class="block-scrollbar">');
            leftBarArr.push(' <div style="width: 100%;height: 140px;text-align: center;line-height: 140px;margin-top: 5px;color: #3d4c63;' +
                'background-color: #c0c0c0;font-size: 14px;">没有发现菜单</div>');
            leftBarArr.push('</div>');
            $(".block-left").html(leftBarArr.join(""));
        }else{
            setLeftBar(lstLeftBar, module);
        }
    })
}

function setLeftBar(lstLeftBar, module){
    var leftBarArr = [];
    leftBarArr.push('<div class="block-scrollbar">');
    leftBarArr.push('    <div class="arrow-btn"><span class="el-icon-arrow-left"></span></div>');
    leftBarArr.push('    <ul class="slide-nav">');
    $.each(lstLeftBar, function(i, n){
        leftBarArr.push('<li id="firstLevel_' + i + '" onclick="openChildren(' + i + ');">');
        if(n.children != null && n.children.length > 0) {
            leftBarArr.push('   <a href="javascript:;" class="v1">');
        }else{
            leftBarArr.push('   <a href="' + getCurrentUrl(n.path, module) + '" class="v1">');
        }
        leftBarArr.push('       <i class="icon_dn icon ' + n.source + '"></i>');
        leftBarArr.push('       <span class="title">' + n.name + '</span>');
        if(n.children != null && n.children.length > 0){
            leftBarArr.push('   <i class="icon-arrow el-icon-arrow-down" style="display: inline;"></i>');
        }else{
            leftBarArr.push('   <i class="icon-arrow el-icon-arrow-down"></i>');
        }
        leftBarArr.push('   </a>');
        // 子菜单处理
        if(n.children != null && n.children.length > 0){
            leftBarArr.push('<div class="slide-nav-subitem">');
            leftBarArr.push('   <ul>');
            $.each(n.children, function(j, m){
                leftBarArr.push('   <li>');
                leftBarArr.push('       <a href="' + getCurrentUrl(m.path, module) + '" class="v2">');
                leftBarArr.push('           <span class="title">' + m.name + '</span>');
                leftBarArr.push('       </a>');
                leftBarArr.push('   </li>');
            });
            leftBarArr.push('   </ul>');
            leftBarArr.push('</div>');
        }
        leftBarArr.push('</li>');
    });
    leftBarArr.push('    </ul>');
    leftBarArr.push('</div>');
    $(".block-left").html(leftBarArr.join(""));
}

function openChildren(i){
    if(!$("#firstLevel_" + i + "").hasClass("active")) {
        $("li[id^='firstLevel_']").removeClass("active");
        $("#firstLevel_" + i + "").addClass("active");
    }else {
        $("li[id^='firstLevel_']").removeClass("active");
    }
}

$(function(){
    // 设置表头菜单
    getTempHead();
    // 设置左边菜单
    var pathname = window.location.pathname;
    if(pathname != "/manage/index.html" && pathname != "/monitor/index.html" && pathname != "/identification/index.html"){
        getLeftBar();
    }
    console.log(pathname,'页面路径')
    //排除不需要登录的页面
    if (pathname != "/login.html" && pathname != "/register.html" && pathname != "/registerNext.html"){
        if (!localStorage.getItem("ACCESS_TOKEN")){
            window.location.href = "/login.html";
        }
    }
    getUrlParams('detail');
})

var lstLeftBarDz = [{name: "业务管理系统-骨干链管理-基础配置", code: "chain_config", systemUrl: "/chain/chainsubmit", currentUrl: "/manage/chain/chainsubmit.html"},
    {name: "业务管理系统-骨干链管理-节点管理", code: "chain_node", systemUrl: "/chain/chainnodement", currentUrl: "/manage/chain/chainnodement.html"},
    {name: "业务管理系统-骨干链管理-合约管理", code: "chain_contract", systemUrl: "/chain/chaincontract", currentUrl: "/manage/chain/chaincontract.html"},
    {name: "业务管理系统-骨干链管理-用户管理", code: "chain_user", systemUrl: "/chain/chainuser", currentUrl: "/manage/chain/chainuser.html"},

    {name: "业务管理系统-子链管理-子链申报管理", code: "chainsubmit", systemUrl: "/chainsub/chainsubment", currentUrl: "/manage/chainsub/chainsubment.html"},
    {name: "业务管理系统-子链管理-子链区块头", code: "chainblock", systemUrl: "/chainsub/chainsubblock", currentUrl: "/manage/chainsub/chainsubblock.html"},
    {name: "业务管理系统-子链管理-子链节点管理", code: "chainsubdoment", systemUrl: "/chainsub/chainsubdoment", currentUrl: "/manage/chainsub/chainsubdoment.html"},
    {name: "业务管理系统-子链管理-子链用户管理", code: "chainsubuser", systemUrl: "/chainsub/chainsubuser", currentUrl: "/manage/chainsub/chainsubuser.html"},
    {name: "业务管理系统-子链管理-子链合约管理", code: "chainsubcontract", systemUrl: "/chainsub/chainsubcontract", currentUrl: "/manage/chainsub/chainsubcontract.html"},

    {name: "角色管理", code: "role", systemUrl: "/authority/role", currentUrl: "/common/role/index.html"},
    {name: "菜单管理", code: "menu", systemUrl: "/system/menu", currentUrl: "/common/system/menu.html"},
    {name: "机构管理", code: "dept", systemUrl: "/system/dept", currentUrl: "/common/system/dept.html"},

    {name: "用户管理", code: "user", systemUrl: "/system/user", currentUrl: "/common/system/user.html"},
    {name: "系统字典", code: "dict", systemUrl: "/system/dict", currentUrl: "/common/system/dict.html"},
    {name: "业务字典", code: "dictbiz", systemUrl: "/system/dictbiz", currentUrl: "/common/system/dictbiz.html"},
    {name: "岗位管理", code: "post", systemUrl: "/system/post", currentUrl: "/common/system/post.html"},
    {name: "数据权限", code: "data_scope", systemUrl: "/authority/datascope", currentUrl: "/common/authority/datascope.html"},
    {name: "接口权限", code: "api_scope", systemUrl: "/authority/apiscope", currentUrl: "/common/authority/apiscope.html"},

    {name: "业务管理系统-附件管理", code: "500", systemUrl: "/resource/attach", currentUrl: "/manage/resource/attach.html"},

    {name: "业务管理系统-认证中心-个人认证", code: "certificate_person", systemUrl: "/certificate/certificateperson", currentUrl: "/manage/authentication/certificateperson.html"},
    {name: "业业务管理系统-认证中心-企业认证", code: "certificate_corp", systemUrl: "/certificate/certificatecorp", currentUrl: "/manage/authentication/certificatecorp.html"},
    {name: "业务管理系统-认证中心-节点认证", code: "certificate_node", systemUrl: "/certificate/certificatenode", currentUrl: "/manage/authentication/certificatenode.html"},

    {name: "标识注册系统-标识注册-标识注册", code: "logoregistry", systemUrl: "/system/logoregistry", currentUrl: "/identification/register.html"},
    {name: "标识注册系统-标识注册-数据模板", code: "identitytemplate", systemUrl: "/system/identitytemplate", currentUrl: "/identification/template.html"},
    {name: "标识注册系统-标识注册-标识查询", code: "logoquery", systemUrl: "/system/logoquery", currentUrl: "/identification/search.html"},

    {name: "运行检测系统-骨干链管理-骨干节点", code: "backboneNode", systemUrl: "/ccms/backboneNode", currentUrl: "/monitor/gulian/node.html"},
    {name: "运行检测系统-骨干链管理-骨干用户", code: "backboneUser", systemUrl: "/ccms/backboneUser", currentUrl: "/monitor/gulian/user.html"},
    {name: "运行检测系统-骨干链管理-骨干合约", code: "backboneContract", systemUrl: "/ccms/backboneContract", currentUrl: "/monitor/gulian/contract.html"},
    {name: "运行检测系统-子链管理-子链管理", code: "childChain", systemUrl: "/ccms/childChain", currentUrl: "/monitor/zilian/manage.html"},
    {name: "运行检测系统-子链管理-子链节点", code: "childChainNode", systemUrl: "/ccms/childChainNode", currentUrl: "/monitor/zilian/node.html"},
    {name: "运行检测系统-子链管理-子链用户", code: "childChainUser", systemUrl: "/ccms/childChainUser", currentUrl: "/monitor/zilian/user.html"},
    {name: "运行检测系统-子链管理-子链合约", code: "childChainContract", systemUrl: "/ccms/childChainContract", currentUrl: "/monitor/zilian/contract.html"},

    {name: "统一认证系统-应用管理-应用设置", code: "11", systemUrl: "/appinfo/list", currentUrl: "/userManager/appcation/setting.html"},
    {name: "统一认证系统-应用管理-安全配置", code: "14", systemUrl: "/appinfo/security", currentUrl: "/userManager/appcation/security.html"},
    {name: "统一认证系统-权限管理-角色时间控制", code: "52", systemUrl: "/authority/time", currentUrl: "/userManager/appcation/time.html"},

    {name: "统一认证系统-用户管理-用户管理", code: "21", systemUrl: "/sys/usermanager", currentUrl: "/userManager/user/manage.html"},
    {name: "统一认证系统-用户管理-管理员管理", code: "22", systemUrl: "/sys/adminmanager", currentUrl: "/userManager/user/admin.html"},
    {name: "统一认证系统-用户管理-黑名单管理", code: "25", systemUrl: "/blackList", currentUrl: "/userManager/user/black.html"},

    {name: "统一认证系统-用户管理-休眠用户管理", code: "23", systemUrl: "/sys/dormantuser", currentUrl: "/userManager/user/dormantuser.html"},
    {name: "统一认证系统-用户管理-审计用户管理", code: "24", systemUrl: "/sys/theAudit", currentUrl: "/userManager/user/theAudit.html"},
    {name: "统一认证系统-用户管理-锁定用户管理", code: "25", systemUrl: "/lockList", currentUrl: "/userManager/user/lockList.html"},
    {name: "统一认证系统-用户管理-长期未使用账号", code: "33", systemUrl: "/longNotUseAccount", currentUrl: "/userManager/user/longNotUseAccount.html"}];

function getCurrentUrl(path, module){
    var currentUrl = ""
    $.each(lstLeftBarDz, function(i, n){
        if(n.systemUrl == path){
            if(path == "/authority/role" || path == "/system/menu" || "/system/user" || "/system/dict" || "/system/dictbiz" || "/system/post"
                || "/authority/datascope" || "/authority/apiscope" || "/system/dept"){
                currentUrl = n.currentUrl + "?module=" + module;
            }else{
                currentUrl = n.currentUrl;
            }
        }
    });
    return currentUrl;
}

function getUuid() {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
}

function getBladeAuth(url){
    getLeftBar();
    /*alert("url：" + url + "state：" + getUrlParams("state") + "code：" + getUrlParams("code"));
    console.log("state：" + getUrlParams("state") + "，code：" + getUrlParams("code"));
    var params = {
        tenant_id: "",
        source: 'user_center',
        state: getUrlParams("state"),
        code: getUrlParams("code"),
        grant_type: "social",
        scope: "all"
    };
    $.ajax({
        url: url,
        type: "post",
        data: params,
        headers: { 'Content-Type': 'application/x-www-form-urlencoded', Authorization: "Basic c2FiZXI6c2FiZXJfc2VjcmV0"},
        dataType: "json",
        success: function (data) {
            console.log(JSON.stringify(data));
            console.log(data.access_token);
            alert("data：" + JSON.stringify(data));
            setLocalStorage("Blade-Auth", data.access_token);
            // getLeftBar();
        },
        error: function (data) {
            alert("error");
            // window.location.href = "/login.html";
        }
    });*/
}

// 设置localstorage
function setLocalStorage(key, val) {
    if (window.localStorage) {
        localStorage.setItem(key, val)
    }
}


// 设置localstorage
function removeLocalStorage(key) {
    if (window.localStorage) {
        localStorage.removeItem(key)
    }
}

function dealInputPlaceholder(){
    if( !('placeholder' in document.createElement('input')) ){
        // 匹配 除type=password以外所有input、textarea
        $('input[placeholder][type!=password],textarea[placeholder]').each(function(){
            var self = $(this),
                text= self.attr('placeholder');
            // 如果内容为空，则写入
            if(self.val()===""){
                self.val(text).addClass('placeholder');
            }

            // 控件激活，清空placeholder
            self.focus(function(){
                if(self.val()===text){
                    self.val("").removeClass('placeholder');
                }
                // 控件失去焦点，清空placeholder
            }).blur(function(){
                if(self.val()===""){
                    self.val(text).addClass('placeholder');
                }
            });
        });
    }
}

function dealData(content){
    var tmpContent = content.substring(18, content.length-4);
    content = content.replace(tmpContent, '...');
    return content;
}

function dealDataNew(content){
    var tmpContent = content.substring(10);
    content = content.replace(tmpContent, '...');
    return content;
}

/**
 * 退出登录
 */
function logout(){
    removeLocalStorage('ACCESS_TOKEN');
    removeLocalStorage('username');
    removeLocalStorage('nickname');
    window.location.href = "/login.html";
}
//  图片地址
$picstr = "http:139.198.15.29:40102/user-center-oauth/file/"